<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <script type="text/javascript">
    console.log("==========函数调用========");
    function add(x,y){
      return x+y;
      console.log("返回后面的代码");
    }
    console.log(add(2,3));

    console.log("==========递归========");
    function fib(num){
      if (num >2){
        return fib(num -2)+fib(num - 1);
      }else{
        return 1;
      }
    }
    console.log(fib(6));

    console.log("==========使用值的地方，就能使用函数========");
    var option = add;
    console.log(option(5,6));

    function a(op) {
      return op;
    }
    a(add(8,9));

    console.log(a(add(8,9)));

    var b={
      name :add,
    }
    console.log(b.name(5,6));

    console.log("==========name属性========");
    console.log("==========属性返回function关键字之后的属性名========");

    function f1(){

    }
    console.log(f1.name);

    var f2 = function () {

    }
    console.log("==========f2========");
    console.log(f2.name);

    console.log("==========length属性========");
    console.log("=========length属性返回函数预期传入的参数个数=========");
    function f3(a,b,c,d,e) {

    }
    console.log(f3.length);
    console.log("==========函数的toString方法返回函数源码========");
    function f4() {
      a();
      b();
      c();
      d();
    }
    console.log(f4.toString());

   console.log("=========利用这点，可以变相实现多行字符串========");
   var f5 = function (val) {
     var arr = val.toString().split('\n');
     return arr.slice(1,arr.length-1).join('\n');
   }
   function f6() {
     /*
     这是一个
     多行注释
     */
   }

    console.log(f5(f6.toString()));
   console.log("==========全局变量========");
   var name ="debang";

   function f7() {
     return name;
   }

   function f8() {
     return name + "is good";
   }
   console.log(f7());
   console.log(f8());
   console.log(f7()+f8());
  </script>
  </body>
</html>
